package com.example.yunxiappbackend.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.yunxiappbackend.pojo.User;
import com.example.yunxiappbackend.service.UserService;
import com.example.yunxiappbackend.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {
    @Autowired
    UserService userService;

    @GetMapping
    public Result<User> get(String username){
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(User::getStatus,1).eq(User::getUsername,username);
        User user = userService.getOne(queryWrapper);
        return Result.success(user);
    }
    @PutMapping
    public Result<String> update(@RequestBody User user){
        log.info(user.toString());
        //会出现id精度丢失问题
        userService.updateById(user);
        return Result.success("更新成功");
    }
}
